{extend name="index/index" /}
{block name="indexmain"}
                <!-- Start of Page Container -->
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://cdn.bootcss.com/tinymce/4.4.3/tinymce.min.js"></script>
{css href="/static/index/css/toastr.min.css" }
{js href="/static/index/js/toastr.min.js"}
<script>tinymce.init({ selector:'textarea' });</script>

<div class="page-container">
                        <div class="container">
                                <div class="row">
                                        <div class="span1 main-listing"></div>
                                        <!-- start of page content -->
                                        <div class="span9 main-listing">

                                               <header class="clearfix">

                                                        <h3 class="">
                                                                <a href="single.html">发布新帖</a>
                                                        </h3>

                                                                
                                                </header> 

                                                <form name="form1" id="form1" class="form-horizontal" action="{:url('index/post/add')}" method="post" enctype="multipart/form-data" >

                                                <table class="table" >
                                                    
                                                    <tr>
                                                        <th>帖子名称</th>
                                                        <td><input type='text' name='postname' id='articlename' style="outline:none;" /></td>

                                                    </tr>
                                                    <tr>
                                                        <th>上传图片</th>
                                                        <td>
                                                                <input type='file'  name="photo" id="photo">
                                                        </td>

                                                    </tr>

                                                </table>
                                                



                                                <textarea id="elm1" ></textarea>
                                                <input type='hidden' name='postcontent' value='' id='inputconc' placeholder=""></input>
                                                <input type='hidden' name='posttext' value='' id='inputcont' placeholder=""></input>
                                                <input type='hidden' name='picname' value='' id='result' placeholder=""></input>
                                                <!-- <input type="button" name="b1" value="上传图片" onclick="fsubmit()" class="btn btn-warning"> -->
                                                <input  type="button" onclick= "doy()" value='发布' class="btn btn-info"/> 
                                                <!-- <button type="button" class="btn btn-success" onclick="check()">发布</button> -->
                                            </form>



                                                
                                        </div>
                                 
                                        
                                </div>
                        </div>
                </div>

<script>
    function doy(){

        // alert(123456);

        var tmpc= tinymce.get('elm1').getContent();      //此函数可获得编辑框内容   
        var tmpt= tinymce.get('elm1').getContent( { 'format' : 'text' } );      //此函数可获得纯文本  
        document.getElementById('inputconc').value = tmpc;
        document.getElementById('inputcont').value = tmpt;

        toastr.options = {
        closeButton: true,// 是否显示关闭按钮
        progressBar: true,// 实现显示计时条
        timeOut: "2000",// 自动关闭时间
        positionClass: "toast-top-right"// 提示位置
        // positionClass: "toast-top-full-width"// 提示位置
        // toast-top-full-width 顶端，宽度铺满整个屏幕
        // toast-top-right  顶端右边
        };


        // alert(123456);


        function check()
        {
            // var artName = document.getElementById('articlename').value;
            var artName = $('#articlename').val();
            var artCon = tinymce.get('elm1').getContent();
            if(artName.length==0 || artCon.length==0){  

                toastr.error('文章名或者内容为空');

            }else
            {


                var data = new FormData($('#form1')[0]);
                $.ajax({
                    url: '/index/post/server',
                    type: 'POST',
                    data: data,
                    dataType: 'JSON',
                    cache: false,
                    processData: false,
                    contentType: false
                }).done(function(ret){
                    if(ret['isSuccess']){
                        // $('#result').html(ret['photo'] );
                        document.getElementById('result').value = ret['photo'];
                        toastr.success('添加文章成功,增加5点积分');
                        setTimeout(function fun(){
                            $('#form1').submit();
                        },2000)
                        // alert('上传成功');

                    }else{

                        toastr.success('添加纯文章成功,增加5点积分');
                        setTimeout(function fun(){
                            $('#form1').submit();
                        },2000)
                        // alert('提交失敗');
                    }
                });


            }  
        }
        check();


        
    }
  </script>

{/block}